package com.ittx.dzt.meituan.util;

import cn.hutool.core.util.StrUtil;
import com.ittx.dzt.business.constant.StoreExtendConstant;
import com.ittx.dzt.edi.dto.PlatformApiParamDTO;
import com.ittx.dzt.sys.util.json.JacksonTool;

import java.util.List;
import java.util.Map;

/**
 * @Author: gywang
 * @Date: 2023/9/7 18:14
 */
public class CyUtil {

    public static String getStatusStr(PlatformApiParamDTO platformApiParamDTO, String orderType) {
        Object status = getStatus(platformApiParamDTO, orderType);
        if (null != status) {
            return String.join(",", (List<String>) status);
        }
        return null;
    }

    public static List<Integer> getStatusList(PlatformApiParamDTO platformApiParamDTO, String orderType) {
        Object status = getStatus(platformApiParamDTO, orderType);
        if (null != status) {
            return (List<Integer>) status;
        }
        return null;
    }

    private static Object getStatus(PlatformApiParamDTO platformApiParamDTO, String orderType) {
        Map<String, Object> extendMap = platformApiParamDTO.getExtendMap();
        if (null != extendMap && extendMap.containsKey(StoreExtendConstant.STATUS_FILTER)) {
            String filterMapStr = extendMap.get(StoreExtendConstant.STATUS_FILTER).toString();
            String filterSetterVal = JacksonTool.toMap(filterMapStr).getOrDefault(orderType, "").toString();
            if (StrUtil.isEmpty(filterSetterVal)) {
                return null;
            }
            Map<String, Object> filterSetterValMap = JacksonTool.toMap(filterSetterVal);
            Map<String, Object> filterMap = (Map<String, Object>) filterSetterValMap.get("filter");
            return filterMap.get("order_status");
        }
        return null;
    }
}
